home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / Common / CAttribute.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  4.5 KB  |  176 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CAttribute.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <5>      3/6/95    TMH        adapt to use Symantic compiler
  13.          <4>     2/27/95    TMH        adapt to use ETO16 universal headers
  14.          <3>     2/14/95    CL        remove globals
  15.          <2>    12/12/94    TMH        added default tag argument value
  16.          <1>     9/20/94    TMH        Abandon RoadsideRest embrace Mercury
  17.                   4/5/94    TMH        xxx put comment here xxx
  18.  
  19.     To Do:
  20. */
  21.  
  22.  
  23. #ifndef __CAttribute__
  24. #define __CAttribute__
  25.  
  26. class CRecordID;
  27.  
  28. #ifndef __BaseTypes__
  29. #include "BaseTypes.h"
  30. #endif
  31.  
  32. #ifndef __CRString__
  33. #include "CRString.h"
  34. #endif
  35.  
  36. #ifndef __OCEAUTHDIR__
  37. #include "OCEAuthDir.h"
  38. #endif
  39.  
  40.  
  41. const long kToolBoxAttrOverHead = 256;        // plenty?
  42. const long kDefaultBuffSize = 1000+kToolBoxAttrOverHead;        // plenty?
  43.  
  44.  
  45. /*
  46.     A very simple class that is binary compatible, (but easier to use) with Attribute
  47.     as defined in OCE.h
  48.         
  49. */
  50.  
  51. //----------------------------------------------------------------------------------------
  52. //                                C A t t r i b u t e
  53. //----------------------------------------------------------------------------------------
  54.  
  55. typedef pascal OSErr (*CAttributeValueCallBack) (long clientData, const Attribute* attrValue);
  56.  
  57.  
  58. class CAttribute {
  59. public:
  60.     CAttributeType            fAttributeType;
  61.     AttributeCreationID        fCID;
  62.     AttributeTag            fTag;
  63.     
  64.     unsigned long            fDataLength;
  65.     void*                    fBytes;
  66.  
  67.  
  68.     CAttributeValueCallBack    fValueCallBack;
  69.     long                    fClientData;
  70.     OSErr                    fCallBackError;
  71.     
  72.     
  73.     operator const Attribute*() const;
  74.     operator Attribute*();
  75.  
  76.     CAttribute();
  77.     CAttribute(Attribute* attr);
  78.     CAttribute(CAttribute* attr);
  79.     CAttribute(CAttributeType& attrType,AttributeTag tag,CreationID *cid = nil);
  80.     CAttribute(short attrTypeIndex, AttributeTag tag='bnry', CreationID *cid = nil);
  81.     CAttribute(char* attrType, AttributeTag tag='bnry', CreationID *cid = nil);
  82.     CAttribute(AttributeTypePtr attrType, AttributeTag tag='bnry', CreationID *cid = nil);
  83.  
  84.  
  85.     ~CAttribute();
  86.  
  87.     CreationID             CID();
  88.     CAttributeType&        Type();
  89.     AttributeTag         Tag();
  90.     
  91.     void                SetType(short attrTypeIndex);
  92.         
  93.     OSErr                 AddAttribute(CRecordID& rid,AddrBlock *serverHint=nil, AuthIdentity identity = 0);    
  94.     OSErr                 ChangeValue(CRecordID& rid,AddrBlock *serverHint=nil, AuthIdentity identity = 0);
  95.     OSErr                 DeleteValue(CRecordID& rid,AddrBlock *serverHint=nil, AuthIdentity identity = 0);
  96.  
  97.     OSErr                 VerifyValueCID(CRecordID& rid,AddrBlock *serverHint=nil, AuthIdentity identity = 0);
  98.         
  99.     OSErr                 Write1Value(CRecordID& rid,void* valueBuf, long valueBufSize, AuthIdentity identity = 0);    
  100.     OSErr                 Read1Value(CRecordID& rid, void* valueBuf, long* valueBufSize,  AuthIdentity identity);
  101.     OSErr                 Read1Value(CRecordID& rid, void* valueBuf, long valueBufSize,  AuthIdentity identity);    // for convenience
  102.  
  103.     OSErr                LookupValues(CRecordID* recordID,CAttributeValueCallBack callBack,long clientData);
  104.  
  105. static    pascal Boolean    __LookupValueCallBack(long clientData, const Attribute* attrValue);
  106.  
  107. };
  108.  
  109.  
  110. // -- Constructors--
  111. inline CAttribute::CAttribute()
  112. {
  113.     memset(this,0,sizeof(Attribute));
  114.     fValueCallBack = 0;
  115. }
  116.  
  117. inline CAttribute::CAttribute(Attribute* attr)
  118. {
  119.     BlockMove((Ptr)attr,(Ptr) this,sizeof(Attribute));
  120.     fValueCallBack = 0;
  121. }
  122. inline CAttribute::CAttribute(CAttribute* cattr)
  123. {
  124.     BlockMove((Ptr)cattr,(Ptr) this,sizeof(Attribute));
  125.     fValueCallBack = 0;
  126.  
  127. }
  128.  
  129. inline CAttribute::CAttribute(CAttributeType& attrType, AttributeTag tag, CreationID *cid)
  130. {
  131.     fAttributeType = attrType;    // copy
  132.     fTag = tag;
  133.     if (cid)
  134.         OCECopyCreationID(cid, &fCID); 
  135.     else
  136.         fCID.source = fCID.seq = 0;
  137.  
  138.     fDataLength = 0;
  139.     fBytes = 0;
  140.  
  141.  
  142.     fValueCallBack = 0;
  143. }
  144.  
  145.  
  146. inline CAttribute::CAttribute(char* attrType, AttributeTag tag, CreationID *cid)
  147. {
  148.     fAttributeType =  attrType;    // copy
  149.     fTag = tag;
  150.     if (cid)
  151.         OCECopyCreationID(cid, &fCID); 
  152.     else
  153.         fCID.source = fCID.seq = 0;
  154.  
  155.     fDataLength = 0;
  156.     fBytes = 0;
  157.  
  158.     fValueCallBack = 0;
  159. }
  160.  
  161.  
  162. inline CreationID        CAttribute::CID()      { return fCID; };
  163. inline AttributeTag        CAttribute::Tag()     { return fTag; };
  164. inline CAttributeType&    CAttribute::Type()     { return fAttributeType; };
  165.  
  166. inline void     CAttribute::SetType(short attrTypeIndex) { fAttributeType = (RString*) OCEGetIndAttributeType(attrTypeIndex); fCID.source = 0; fCID.seq = 0;};
  167.  
  168. inline CAttribute::operator const Attribute*() const        { return (const Attribute*) this; };
  169. inline CAttribute::operator Attribute*() { return (Attribute*) this; };
  170.  
  171. inline OSErr CAttribute::Read1Value(CRecordID& rid, void* valueBuf, long valueBufSize,  AuthIdentity idendtity) { return this->Read1Value(rid,valueBuf,&valueBufSize, idendtity); };
  172.  
  173.  
  174.  
  175. #endif __CAttribute__
  176.